<?php
class UserModel
{
	public static function GetUser()
	{
		include_once 'sql_connector.php';
		$db = SQLConnector::connect();

		$query = "select * from users";
		try {
			$result = $db->fetchAll($query);
		}
		catch(Zend_Db_Exception $e)
		{
			echo 'DB ERROR : '.$e->getMessage();
		}
		
		return $result;
	}
	
	public static function GetNumUser()
	{
		include_once 'sql_connector.php';
		$db = SQLConnector::connect();

		$query = "select count(id) from users";
		try {
			$result = $db->fetchOne($query);
		}
		catch(Zend_Db_Exception $e)
		{
			echo 'DB ERROR : '.$e->getMessage();
		}
		
		return $result;
	}
	
	public static function GetIDFromName($name)
	{
		include_once 'sql_connector.php';
		$db = SQLConnector::connect();
		$db->query("SET NAMES 'utf8'");

		$query = "select id from users where name = '$name'";
		try {
			$result = $db->fetchOne($query);
		}
		catch(Zend_Db_Exception $e)
		{
			echo 'DB ERROR : '.$e->getMessage();
		}
		
		return $result;
	}
	
	public static function GetUserFromID($id)
	{
		include_once 'sql_connector.php';
		$db = SQLConnector::connect();
		$db->query("SET NAMES 'utf8'");

		$query = "select * from users where id = '$id'";
		try {
			$result = $db->fetchRow($query);
		}
		catch(Zend_Db_Exception $e)
		{
			echo 'DB ERROR : '.$e->getMessage();
		}
		
		return $result;
	}
}